import React, { Component } from 'react'
import Header from '../../components/Header/Header'
import {reqcate,reqbanner,reqgoods} from '../../request/api'
import Banner from './components/Banner/Banner'
import Cate from './components/Cate/Cate'
import Goods from './components/Goods/Goods'
export default class Home extends Component {
    constructor(){
        super();
        this.state={
            cates:[],
            banner:[],
            goods:[],
            n:0
        }
    }
    changeN(n){
        this.setState({
            n
        })
    }
    render() {
        const {cates,banner,goods,n}=this.state
        return (
            <div>
                <Header title="首页"></Header>
                <Cate cates={cates}></Cate>
                <Banner banner={banner}></Banner>
                <Goods goods={goods} n={n} changeN={n=>{this.changeN(n)}}></Goods>
            </div>
        )
    }
    componentDidMount(){//请求数据使用
        reqgoods().then(d=>{
            if(d.data.code===200){
                this.setState({goods:d.data.list})
            }
        })

        reqbanner().then(d=>{
            if(d.data.code===200){
                this.setState({banner:d.data.list})
            }
        })

        reqcate().then(d=>{
            if(d.data.code===200){
                this.setState({cates:d.data.list})
            }
        })
    }
}
